package example.file;

import java.io.File;

/**
 * Created by lenovo on 2016/11/4 0004.
 * File 类的 dir.isDirectory() 和 dir.list() 方法来遍历目录
 */
public class ListDir {
    public static void main(String[] argv)
            throws Exception {
        System.out.println("遍历目录");
        File dir = new File("/www/java"); //要遍历的目录
        visitAllDirsAndFiles(dir);
    }

    private static void visitAllDirsAndFiles(File dir) {
        System.out.println(dir);
        if (dir.isDirectory()) {
            String[] children = dir.list();
            for (String aChildren : children) {
                visitAllDirsAndFiles(new File(dir, aChildren));
            }
        }
    }
}
